<template>
	<view class="requirementDetails">
		<view class="">
			<view class="top" @tap="imgPreview">
				<image
					:src="data.httpUrl+'/app/file/viewFile?fileId='+data.obj.appVpsDemand.attachmentIds.split(',')[0]"
					mode="aspectFill">
				</image>
			</view>
			<view class="details">
				<view class="top">
					<view class="left">
						{{data.obj.appVpsDemand.title}}
						<text>{{data.obj.appVpsDemand.sellType == 'OFFLINE'?'线下':'线上'}}</text>
						<text>兼职</text>
					</view>
					<image class="detailsavatarId" :src="data.httpUrl+'/app/file/viewFile?fileId='+data.obj.avatarId"
						mode="aspectFill">
					</image>
					<!-- 已评价 -->
				</view>
				<view class="top_2">
					<view class="">
						<image src="/static/img/index/163.png" mode="widthFix"></image>
						{{data.obj.authenticationFlag == 'Y'?'已认证':'未认证'}}
					</view>
					<view class="">
						<image src="/static/img/index/164.png" mode="widthFix"></image>
						{{data.obj.credit}}
					</view>
					<view class="">
						<image src="/static/img/index/165.png" mode="widthFix"></image>
						{{data.obj.bondBalance>=10000?Math.floor(data.obj.bondBalance/10000)+'万+':data.obj.bondBalance}}
					</view>
					<view class="">
						<image src="/static/img/index/176.png" mode="widthFix"></image>
						{{data.obj.avgScoring || 0}}
					</view>
				</view>
				<view class="price">
					{{data.obj.appVpsDemand.price}}{{data.obj.appVpsDemand.pricingUnit?'/'+data.obj.appVpsDemand.pricingUnit:''}}<text>{{data.obj.appVpsDemand.number || ''}}{{data.obj.appVpsDemand.pricingUnit}}</text>
				</view>
				<view class="time" v-if="data.obj.appVpsDemand.serviceTime" style="color: #595959;
						font-size: 32rpx;">
					需求时间
					<text style="color: #595959;
						font-size: 32rpx;">{{data.obj.appVpsDemand.serviceTime}}</text>
				</view>
				<view class="bot">
					<view class="left">
						<image src="/static/img/index/156.png" mode="widthFix"></image>
						地址
					</view>
					<view class="right">
						{{data.obj.appVpsDemand.address}}
					</view>
				</view>
				<view class="fromYou">
					距您{{data.obj.distance}}km
				</view>
			</view>
			<view class="describe">
				需求描述
				<text>{{data.obj.appVpsDemand.content}}</text>
			</view>
		</view>
		<view class="bot">
			<text @tap="customerService">联系对方</text>
			<text @tap="receivingOrders">接单</text>
		</view>
	</view>
</template>

<script lang="ts" setup>
	import { onLoad } from '@dcloudio/uni-app';
	import { getVpsDemandDetails, createVpsOrder } from '@/utils/api/map'
	import {
		reactive,
	} from 'vue';
	import {
		setDialogView
	} from '@/utils/dialogView.ts'
	const data = reactive<any>({
		httpUrl: getApp().globalData.baseUrl,
		obj: { appVpsDemand: {} }
	})
	onLoad(({ id, longitude, latitude }) => {
		data.id = id;
		setDialogView('ACCESS_FINE_LOCATION').then(res => {
			if (res == 1) {
				uni.getLocation({
					type: 'gcj02',
					geocode: true,
					success: function (res) {
						getVpsDemandDetails({ data: { id, longitude: res.longitude, latitude: res.latitude } }).then((res) => {
							console.log(res.data)
							data.obj = res.data;
						})
					},
					fail: () => {
						getVpsDemandDetails({ data: { id, longitude, latitude } }).then((res) => {
							console.log(res.data)
							data.obj = res.data;
						})
					}
				})
			} else {
				getVpsDemandDetails({ data: { id, longitude, latitude } }).then((res) => {
					console.log(res.data)
					data.obj = res.data;
				})
			}
		})


	})
	const imgPreview = () => {
		uni.previewImage({
			urls: data.obj.attachmentIds.map(item => data.httpUrl + '/app/file/viewFile?fileId=' + item)
		})
	}
	const customerService = () => {
		// data.info.serviceUserId = '1848031351512059906'
		const conversationID = `C2C${data.obj.appVpsDemand.userId}`;
		uni.navigateTo({ url: `/pages/TUIKit/components/TUIChat/index?conversationID=${conversationID}&userId=${data.obj.appVpsDemand.userId}` });
	}
	const receivingOrders = () => {
		uni.showModal({
			title: '提示',
			content: '是否接单?',
			success: (e) => {
				if (e.confirm) {
					uni.showLoading({
						title: '加载中...',
						mask: true
					})
					createVpsOrder({ data: { vpsDemandId: data.id } }).then((res) => {
						if (res.code == 200) {
							uni.showToast({
								title: '接单成功!',
								icon: 'none'
							})
							uni.$emit('searchRequirements')
							setTimeout(() => {
								uni.redirectTo({
									url: '/pages/demandOrder/index'
								})
							}, 1000)
						}
					})
				}
			}
		})
	}
</script>

<style lang="scss">
	.detailsavatarId {
		width: 100rpx;
		height: 100rpx;
		border-radius: 50%;
	}

	.fromYou {
		display: flex;
		justify-content: flex-end;
		font-size: 24rpx;
		color: #8C8C8C;
		margin-top: 10rpx;
	}

	.top_2 {
		display: flex;
		margin: 20rpx 0 24rpx 0;

		view {
			border-radius: 8rpx;
			padding-right: 16rpx;
			margin-right: 16rpx;
			display: flex;
			font-size: 24rpx;
			align-items: center;

			image {
				width: 66rpx;
				margin-right: 10rpx;
			}
		}

		view:nth-of-type(1) {
			margin-right: 15rpx;
			color: #6B64D3;
			background: #F0E6FF;
		}

		view:nth-of-type(4) {
			margin-right: 15rpx;
			background: #eb5f7d33;
			color: red;
		}

		view:nth-of-type(2) {
			margin-right: 15rpx;
			background: #CEEFFF;
			color: #40AFFF;
		}

		view:nth-of-type(3) {
			background: #FFFDCF;
			color: #FFCC40;
			margin-right: 15rpx;
		}
	}

	.requirementDetails {
		height: 100vh;
		display: flex;
		flex-direction: column;
		padding: 30rpx;

		>.bot {
			padding: 8rpx 32rpx 20rpx 32rpx;
			background: #fff;
			display: flex;
			justify-content: space-between;

			text:nth-of-type(1) {
				background: #F4F6FA;
				color: #595959;
			}

			text:nth-of-type(2) {
				background: #6B64D3;
				color: #fff;
			}

			text {
				display: inline-block;
				width: 45%;
				line-height: 80rpx;
				text-align: center;
				font-size: 32rpx;
				border-radius: 80rpx;
			}
		}

		>view:nth-of-type(1) {
			flex: 1;

			>.top {
				height: 420rpx;
				background: #ccc;
				display: flex;
				align-items: center;
				justify-content: space-between;

				image {
					width: 100%;
					height: 100%;
				}
			}

			>.details {
				border-radius: 24rpx;
				padding: 24rpx;
				border: 2rpx solid #333;
				margin-top: 32rpx;

				.top {
					display: flex;
					align-items: center;
					justify-content: space-between;

					.left {
						font-size: 36rpx;
						display: flex;
						align-items: center;
						flex: 1;
						margin-right: 20rpx;

						text {
							width: 80rpx;
							line-height: 48rpx;
							text-align: center;
							margin-left: 12rpx;
							background: #F4F6FA;
							border-radius: 8rpx;
							font-size: 24rpx;
							color: #8C8C8C;
						}
					}

					color: #8C8C8C;
				}

				.price {
					display: flex;
					align-items: center;
					font-size: 32rpx;
					color: #6B64D3;
					margin: 24rpx 0;

					text {
						width: 70rpx;
						line-height: 48rpx;
						text-align: center;
						border-radius: 8rpx;
						background: #E4E2FC;
						color: #6B64D3;
						font-size: 24rpx;
						margin-left: 12rpx;
					}
				}

				.bot {
					display: flex;
					align-items: center;
					justify-content: space-between;

					.left {
						display: flex;
						align-items: center;
						color: #595959;
						font-size: 32rpx;

						image {
							width: 48rpx;
							margin-right: 8rpx;
						}
					}

					.right {
						flex: 1;
						margin-left: 20rpx;
						color: #595959;
						font-size: 32rpx;
						text-align: right;
					}

				}
			}

			>.describe {
				margin-top: 64rpx;
				font-size: 42rpx;
				color: #000000;
				display: flex;
				flex-direction: column;

				text {
					color: #595959;
					font-size: 32rpx;
					margin-top: 16rpx;
					line-height: 1.5;
				}
			}
		}


	}

	.time {
		display: flex;
		justify-content: space-between;
		margin-bottom: 10rpx;
	}
</style>